package com.bobby.dao.impl;

import com.bobby.dao.BaseDao;
import com.bobby.dao.OrderDao;
import com.bobby.pojo.Order;

import java.sql.SQLException;
import java.util.List;

/**
 * @Description TODO
 * @Date 2020/8/16 15:04
 * @Created wenjunpei
 */
public class OrderDaoImpl extends BaseDao<Order> implements OrderDao {

    @Override
    public void saveOrder(Order order) throws SQLException {
        String sql = "insert into t_order(order_id,create_time,price,status,user_id) values(?,?,?,?,?)";
        update(sql,order.getOrderId(),order.getCreateTime(),order.getPrice(),order.getStatus(),order.getUserId());
    }

    @Override
    public List<Order> queryOrders() throws SQLException {
        String sql = "select order_id orderId , create_time createTime, price , status , user_id userId from t_order";
        return queryForList(sql);
    }

    @Override
    public void changerOrderStatus(String orderId, Integer status) throws SQLException {
        String sql = "update t_order set status = ? where order_id = ?";
        update(sql,status,orderId);
    }

    @Override
    public List<Order> queryOrdersByUserId(Integer userId) throws SQLException {
        String sql = "select order_id orderId , create_time createTime, price , status , user_id userId from t_order where user_id = ?";
        return queryForList(sql,userId);
    }
}
